// pages/order/list/index.js
import {
  getOrderList
} from '../../../api/order'
Page({
  // 页面的初始数据
  data: {
    orderList: [],
    total: null,
    isLoading: false,
    params: {
      page: '1',
      limit: '10'
    }
  },
  onShow() {
    this.getOrderList()
  },
  // 获取订单列表数据
  async getOrderList() {
    this.setData({
      isLoading: true
    })
    const {
      data: {
        records,
        total
      }
    } = await getOrderList(this.data.params)
    this.setData({
      isLoading: false
    })
    this.setData({
      orderList: [...this.data.orderList, ...records],
      total
    })
  },
  onReachBottom() {
    if (this.data.isLoading) return
    // goodslist的长度大于总条数则return
    if (this.data.orderList.length >= this.data.total) return wx.toast({
      title: '加载完毕',
      icon: 'success'
    })
    // 每次触发则页码数+1
    this.setData({
      "params.page": `${parseInt(this.data.params.page)+1}`
    })

    this.getOrderList()
  }
})